package com.example.thirdhomework

import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Bitmap
import android.os.Bundle
import android.os.PersistableBundle
import android.provider.MediaStore
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

const val FIRST_MSG="FIRST_MSG"
const val SECOND_MSG="SECOND_MSG"
const val REQUEST_CODE_PHOTO_CAPTURE=100
const val REQUEST_IMAGE_CAPTURE=1

class MainActivity : AppCompatActivity() {
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val first: Button = findViewById(R.id.first)
        first.setOnClickListener {
            val intent = Intent(this, SecondActivity::class.java)
            val editText: EditText = findViewById(R.id.editText)
            intent.putExtra(FIRST_MSG, editText.text.toString())
            startActivity(intent)
        }

        val second: Button = findViewById(R.id.second)
        second.setOnClickListener {
            val intent = Intent(this, ThirdActivity::class.java)
            startActivityForResult(intent, 0)
        }
        val fourth:Button=findViewById(R.id.fourth)
        fourth.setOnClickListener {
            val intent=Intent(this, FourthActivity::class.java)
            startActivityForResult(intent, REQUEST_CODE_PHOTO_CAPTURE)
        }
        val fifth:Button=findViewById(R.id.fifth)
        fifth.setOnClickListener {
            val intent=Intent(this, FifthActivity::class.java)
            startActivity(intent)
        }

    }
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 0) {
            if (resultCode == 1) {
                val textView: TextView = findViewById(R.id.textView)
                textView.text = data?.getStringExtra(SECOND_MSG)
            }
        }
    }



}